package uiframework;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.MouseListener;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;


import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;

import utilities.Direction;

import dbhandeling.Crude;

public class UIFrameWork extends Crude{
	
	public static JToolBar addToolBar(JPanel parentpanel,SpringLayout springlayout)
	{
		JToolBar toolBar = new JToolBar();
		toolBar.setBorder(null);
		toolBar.setOrientation(SwingConstants.VERTICAL);
		springlayout.putConstraint(SpringLayout.SOUTH, toolBar, 0, SpringLayout.SOUTH, parentpanel);
		springlayout.putConstraint(SpringLayout.NORTH, toolBar, 0, SpringLayout.NORTH, parentpanel);
		springlayout.putConstraint(SpringLayout.WEST, toolBar, 0, SpringLayout.WEST, parentpanel);
		springlayout.putConstraint(SpringLayout.EAST, toolBar, 180, SpringLayout.WEST,parentpanel);
		parentpanel.add(toolBar);
		return toolBar;
		
	}
	
	public static JLabel[] setLeftMenu(String[]menunames,JToolBar toolbar,Dimension maximumSize)
	{
		JLabel[]label=new JLabel[menunames.length];
		
		for(int i=0;i<label.length;i++)
		{
			label[i]=new JLabel(menunames[i],JLabel.CENTER);
			label[i].setMaximumSize(maximumSize);
			toolbar.add(label[i]);
			toolbar.addSeparator();
			// GET PARENT OF TOOL BAR WHICH IS OUR MOUSE LISTENER
		   MouseListener parent=(MouseListener) toolbar.getParent();
			
			
			label[i].addMouseListener(parent);
			
		}
		
		return label;
	}
	
	
	public static void styleLeftMenu(JLabel[]labels,Font f,Color backGround,Color foreGround)
	{
	
		for(int i=0;i<labels.length;i++)
		{
			
			labels[i].setFont(f);
			if(backGround!=null)
				labels[i].setBackground(backGround);
			if(foreGround!=null)
				labels[i].setForeground(foreGround);
			
		}
		
		
		//btnsalesReport.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
	}
	
	
	public static void setReportComponent(SpringLayout springLayout,JPanel panel,JPanel parentPanel,int componentCount)
	{
		
		if(parentPanel.getComponentCount()==componentCount)
			parentPanel.remove(componentCount-1);
		
		springLayout.putConstraint(SpringLayout.SOUTH, panel, 0, SpringLayout.SOUTH,parentPanel);
		springLayout.putConstraint(SpringLayout.WEST, panel, 180, SpringLayout.WEST,parentPanel);
		springLayout.putConstraint(SpringLayout.EAST, panel, 0, SpringLayout.EAST, parentPanel);
		springLayout.putConstraint(SpringLayout.NORTH, panel, 0, SpringLayout.NORTH, parentPanel);
		parentPanel.add(panel);
		parentPanel.revalidate();
		parentPanel.repaint();
	}
	
	public static void setFormComponent(SpringLayout springLayout,JPanel panel,JPanel parentPanel,int componentCount)
	{
		
		System.out.println(parentPanel.getComponentCount());
		if(parentPanel.getComponentCount()==componentCount)
			parentPanel.remove(componentCount-1);
		
		springLayout.putConstraint(SpringLayout.SOUTH, panel, -3, SpringLayout.SOUTH, parentPanel);
		springLayout.putConstraint(SpringLayout.HORIZONTAL_CENTER, panel, 0, SpringLayout.HORIZONTAL_CENTER, parentPanel);
		springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, panel, 0, SpringLayout.VERTICAL_CENTER, parentPanel);
		springLayout.putConstraint(SpringLayout.NORTH, panel, 3, SpringLayout.NORTH, parentPanel);
		parentPanel.add(panel);
		parentPanel.revalidate();
		parentPanel.repaint();
	}
	
	
	

}
